/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.shop.web.shop;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.shop.entity.shop.HkShopLuckyBurstCouponAdv;
import com.thinkgem.jeesite.modules.hk.shop.service.shop.HkShopLuckyBurstCouponAdvService;

/**
 * 乐够幸运爆款优惠券广告Controller
 * @author 李欣荣
 * @version 2018-10-11
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/shop/hkShopLuckyBurstCouponAdv")
public class HkShopLuckyBurstCouponAdvController extends BaseController {

	@Autowired
	private HkShopLuckyBurstCouponAdvService hkShopLuckyBurstCouponAdvService;
	
	@ModelAttribute
	public HkShopLuckyBurstCouponAdv get(@RequestParam(required=false) String id) {
		HkShopLuckyBurstCouponAdv entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkShopLuckyBurstCouponAdvService.get(id);
		}
		if (entity == null){
			entity = new HkShopLuckyBurstCouponAdv();
		}
		return entity;
	}
	
	@RequiresPermissions("shop:shop:hkShopLuckyBurstCouponAdv:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkShopLuckyBurstCouponAdv hkShopLuckyBurstCouponAdv, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkShopLuckyBurstCouponAdv> page = hkShopLuckyBurstCouponAdvService.findPage(new Page<HkShopLuckyBurstCouponAdv>(request, response), hkShopLuckyBurstCouponAdv); 
		model.addAttribute("page", page);
		return "hk/shop/shop/hkShopLuckyBurstCouponAdvList";
	}

	@RequiresPermissions("shop:shop:hkShopLuckyBurstCouponAdv:view")
	@RequestMapping(value = "form")
	public String form(HkShopLuckyBurstCouponAdv hkShopLuckyBurstCouponAdv, Model model) {
		model.addAttribute("hkShopLuckyBurstCouponAdv", hkShopLuckyBurstCouponAdv);
		return "hk/shop/shop/hkShopLuckyBurstCouponAdvForm";
	}

	@RequiresPermissions("shop:shop:hkShopLuckyBurstCouponAdv:edit")
	@RequestMapping(value = "save")
	public String save(HkShopLuckyBurstCouponAdv hkShopLuckyBurstCouponAdv, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkShopLuckyBurstCouponAdv)){
			return form(hkShopLuckyBurstCouponAdv, model);
		}
		hkShopLuckyBurstCouponAdvService.save(hkShopLuckyBurstCouponAdv);
		addMessage(redirectAttributes, "保存幸运爆款优惠券广告成功");
		return "redirect:"+Global.getAdminPath()+"/shop/shop/hkShopLuckyBurstCouponAdv/?repage";
	}
	
	@RequiresPermissions("shop:shop:hkShopLuckyBurstCouponAdv:edit")
	@RequestMapping(value = "delete")
	public String delete(HkShopLuckyBurstCouponAdv hkShopLuckyBurstCouponAdv, RedirectAttributes redirectAttributes) {
		hkShopLuckyBurstCouponAdvService.delete(hkShopLuckyBurstCouponAdv);
		addMessage(redirectAttributes, "删除幸运爆款优惠券广告成功");
		return "redirect:"+Global.getAdminPath()+"/shop/shop/hkShopLuckyBurstCouponAdv/?repage";
	}

}